﻿using SharpDX;
using SharpDX.Direct2D1;
using System;
using System.Collections.Generic;
using System.Text;

namespace SpaceBattle
{
    class SpaceShip
    {
        public RenderTarget renderTarget;
        public Factory factory;

        public int speed = 10; // pixels/sec

        private Bitmap ShipImage = null;
        private DrawingPointF CenterPoint = new DrawingPointF(0, 0);
        private RectangleF BoundingBox;
        private float Scale = 1.0f;

        public SpaceShip(RenderTarget renderTarget, Factory factory)
        {
            this.renderTarget = renderTarget;
            this.factory = factory;

            ShipImage = Utilities.LoadFromFile(renderTarget, "../../images/spaceship.png");
            UpdateShipBox();
        }

        public void SetScale(float scale)
        {
            Scale = scale;
            UpdateShipBox();
        }

        public void Move(DrawingPointF moveVector)
        {
            CenterPoint = new DrawingPointF(CenterPoint.X + moveVector.X, CenterPoint.Y + moveVector.Y);
            UpdateShipBox();
        }

        public void Draw()
        {
            renderTarget.DrawBitmap(ShipImage, BoundingBox, 1.0f, BitmapInterpolationMode.Linear);
        }

        private void UpdateShipBox()
        {
            BoundingBox.Left = CenterPoint.X - ShipImage.PixelSize.Width * Scale / 2;
            BoundingBox.Right = CenterPoint.X + ShipImage.PixelSize.Width * Scale / 2;
            BoundingBox.Top = CenterPoint.Y - ShipImage.PixelSize.Height * Scale / 2;
            BoundingBox.Bottom = CenterPoint.Y + ShipImage.PixelSize.Height * Scale / 2;
        }

        public void SetCenter(DrawingPointF newCenter)
        {
            CenterPoint = newCenter;
            UpdateShipBox();
        }
    }
}
